Imports CasClientBase
Imports ccapps.Util
Imports ccapps.persistent.OIV_Baglilik
Imports ccapps.persistent.myDBConn

Namespace Web.page

    Public Class CepDestek_Gateway
        Inherits [lib].BasePage

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents ltlAlert As System.Web.UI.WebControls.Literal
        Protected WithEvents Button66 As System.Web.UI.WebControls.Button
        Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
        Protected WithEvents txt_Custcode As System.Web.UI.WebControls.TextBox
        Protected WithEvents txt_Msisdn As System.Web.UI.WebControls.TextBox
        Protected WithEvents ContentPaneFooter1 As Library.WebControls.ContentPaneFooter
        Protected WithEvents Table1 As System.Web.UI.HtmlControls.HtmlTable
        Protected WithEvents tblMainContent As System.Web.UI.HtmlControls.HtmlTable
        Protected WithEvents trCustomerSelection As System.Web.UI.HtmlControls.HtmlTableRow
        Protected WithEvents trCustomerInfo As System.Web.UI.HtmlControls.HtmlTableRow
        Protected WithEvents lbl_CustomerName As System.Web.UI.WebControls.Label
        Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
        'Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton

        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

        Private _CPFConfirmCliecked As Boolean

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.PageTitle = "Cepdestek"
            Me.HelpDocName = ""

            Me.TextBox1.Style("display") = "'none'"
        End Sub

        Private Sub ContentPaneFooter1_Confirmed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContentPaneFooter1.Confirmed

            Me._CPFConfirmCliecked = True

            If Me.TextBox1.Text = "0" Then
                If txt_Custcode.Text.Trim() = "" AndAlso txt_Msisdn.Text.Trim() = "" Then
                    Message = "alert('CustCode veya MSISDN giriniz!'); "
                    Return
                End If

                If txt_Custcode.Text.Trim() = "" Then
                    txt_Custcode.Text = GetCustcodeFromMSISDN(txt_Msisdn.Text.Trim())
                End If

                Dim l_result As String
                Dim l_SME_LA_Flag, l_root_custcode As String
                l_result = CheckCustcode(txt_Custcode.Text, l_root_custcode, l_SME_LA_Flag)
                If l_result <> "OK" Then
                    Message = "alert('" + l_result + "'); "
                Else
                    Me.ContentPaneFooter1.ConfirmButton.Text = "Rapor"
                    Me.TextBox1.Text = "1"
                    Me.lbl_CustomerName.Text = GetCustomerData(l_root_custcode)
                End If

            Else
                Session("XLS_Data") = getDataSource(Me.txt_Custcode.Text)
                Response.Redirect("ExcelGoster.aspx")
            End If

        End Sub

        REM BSCS_6 Old version	
        REM Private Function getDataSource(ByVal custCode As String) As DataTable
        REM Dim query As String = "select " & _
        REM vbNewLine & "       fn_coid_to_msisdn(co.co_id) msisdn, " & _
        REM vbNewLine & "       cur.ch_status, " & _
        REM vbNewLine & "       co.tmcode, " & _
        REM vbNewLine & "       tm.des tmdes, " & _
        REM vbNewLine & "       sn.des h_segment, " & _
        REM vbNewLine & "       round(th.corp_monthly_threshold*1.43) taahhut, " & _
        REM vbNewLine & "       to_date(csmin.cs_entdate,'dd.mm.yyyy') start_date, " & _
        REM vbNewLine & "       add_months(to_date(csmin.cs_entdate,'dd.mm.yyyy'),24) end_date " & _
        REM vbNewLine & "from   customer_all cua, " & _
        REM vbNewLine & "       contract_all co, " & _
        REM vbNewLine & "       curr_co_status cur, " & _
        REM vbNewLine & "       contr_services csmin, " & _
        REM vbNewLine & "       mputmtab tm, " & _
        REM vbNewLine & "       mpusntab sn, " & _
        REM vbNewLine & "       sysadm.it_handset_threshold th " & _
        REM vbNewLine & "where  co.customer_id = cua.customer_id " & _
        REM vbNewLine & "       and cua.custcode = '" & custCode & "' " & _
        REM vbNewLine & "       and cur.co_id=co.co_id " & _
        REM vbNewLine & "       and tm.tmcode=co.tmcode " & _
        REM vbNewLine & "       and tm.vscode=(select max(vscode) from mputmtab tm2 where tm2.tmcode=co.tmcode) " & _
        REM vbNewLine & "      and csmin.co_id=co.co_id " & _
        REM vbNewLine & "       and csmin.sncode in (306,307,308,309,310,311,312,313,335) " & _
        REM vbNewLine & "       and csmin.cs_seqno=(select min(cs_seqno) from contr_services cs where cs.co_id=csmin.co_id and cs.sncode=csmin.sncode) " & _
        REM vbNewLine & "       and sn.sncode=csmin.sncode " & _
        REM vbNewLine & "       and th.corporate_handset_sncode=csmin.sncode"

        REM Return persistent.myDBConn.myORATable(query)
        REM End Function

        REM Begin : BSCS_IX_R3 New Version
        Private Function getDataSource(ByVal custCode As String) As DataTable
            Dim query As String = "select " & _
            vbNewLine & "       fn_coid_to_msisdn(co.co_id) msisdn, " & _
            vbNewLine & "       cur.ch_status, " & _
            vbNewLine & "       co.tmcode, " & _
            vbNewLine & "       tm.des tmdes, " & _
            vbNewLine & "       sn.des h_segment, " & _
            vbNewLine & "       round(th.corp_monthly_threshold*1.43) taahhut, " & _
            vbNewLine & "       to_date(ps.entry_date,'dd.mm.yyyy') start_date, " & _
            vbNewLine & "       add_months(to_date(ps.entry_date,'dd.mm.yyyy'),24) end_date " & _
            vbNewLine & "from   customer_all cua, " & _
            vbNewLine & "       contract_all co, " & _
            vbNewLine & "       curr_co_status cur, " & _
            vbNewLine & "       profile_service  ps, " & _
   vbNewLine & "       pr_serv_status_hist pss, " & _
            vbNewLine & "       mputmtab tm, " & _
            vbNewLine & "       mpusntab sn, " & _
            vbNewLine & "       sysadm.it_handset_threshold th " & _
            vbNewLine & "where  ps.profile_id = pss.profile_id " & _
   vbNewLine & "       and ps.co_id = pss.co_id " & _
   vbNewLine & "       and ps.sncode = pss.sncode " & _
   vbNewLine & "       and ps.status_histno = pss.histno " & _
   vbNewLine & "       and co.customer_id = cua.customer_id " & _
            vbNewLine & "       and cua.custcode = '" & custCode & "' " & _
            vbNewLine & "       and cur.co_id=co.co_id " & _
            vbNewLine & "       and tm.tmcode=co.tmcode " & _
            vbNewLine & "       and tm.vscode=(select max(vscode) from mputmtab tm2 where tm2.tmcode=co.tmcode) " & _
            vbNewLine & "      and ps.co_id=co.co_id " & _
            vbNewLine & "       and ps.sncode in (306,307,308,309,310,311,312,313,335) " & _
            vbNewLine & "       and sn.sncode=ps.sncode " & _
            vbNewLine & "       and th.corporate_handset_sncode=ps.sncode"

            Dim dtTemp As DataTable = persistent.myDBConn.myORATable(query)
            Return dtTemp
        End Function
        REM End : BSCS_IX_R3 New Version

        Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
            Me.trCustomerSelection.Visible = Me.ContentPaneFooter1.ConfirmButton.Text = "Getir"
            Me.trCustomerInfo.Visible = Not Me.trCustomerSelection.Visible
        End Sub
    End Class
End Namespace

